package cqrtplm.listener;

import cn.hutool.extra.spring.SpringUtil;
import com.hustcad.plm.pdm.workflow.annotion.CustomListener;
import com.hustcad.plm.pdm.workflow.model.constant.ProcessConstant;
import cqrtplm.service.RTChgListenerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;

import java.math.BigInteger;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : pieStar
 * @create 2025/7/22 21:54
 */
@Slf4j
@CustomListener(category = "润通", description = "状态需求表数据下发MOM")
public class RTSendStatusRequireToMOMListener implements ExecutionListener {
    @Override
    public void notify(DelegateExecution delegateExecution) {
        long start = System.currentTimeMillis();
        String workFlowContainerId = delegateExecution.getProcessInstanceBusinessKey();
        log.info("----------润通----状态需求表数据下发MOM------开始------workFlowContainerId:{}----->>>", workFlowContainerId);
        log.info("开始时间：", start);
        if (StringUtils.isBlank(workFlowContainerId)) {
            workFlowContainerId = delegateExecution.getVariable(ProcessConstant.WORK_FLOW_CONTAINER_ID).toString();
        }
        RTChgListenerService rtChgListenerService = SpringUtil.getBean(RTChgListenerService.class);
        rtChgListenerService.sendStatusRequireToMOM(new BigInteger(workFlowContainerId));
        log.info("----------润通----状态需求表数据下发MOM------结束------", System.currentTimeMillis());
    }
}
